<template>
  <el-dialog
    title="查询详情"
    :visible.sync="dialogFormVisible"
    :close-on-click-modal="false"
  >
    <el-form
      ref="form"
      label-width="80px"
      :model="user"
      :rules="rules"
      v-loading="loadDataing"
    >
      <el-form-item label="用户账号" prop="accountNo">
        <el-input v-model="user.accountNo" readonly></el-input>
      </el-form-item>
      <el-form-item label="用户名称" prop="realName">
        <el-input v-model="user.realName" readonly></el-input>
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="user.remark" readonly></el-input>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="close">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import * as api from "@/api/user";
export default {
  name: "user-add",
  data() {
    return {
      user: {
        id: "",
        accountNo: "",
        realName: "",
        remark: "",
        createUser: "",
        updateUser: "",
      },
      rules: {
        accountNo: [
          { required: true, message: "用户账号不能为空", trigger: "blur" },
        ],
        realName: [
          { required: true, message: "用户名称不能为空", trigger: "blur" },
        ],
      },
      loading: false,
      dialogFormVisible: false,
      loadDataing: false,
    };
  },
  methods: {
    close() {
      this.dialogFormVisible = false;
    },

    show(userId) {
      this.dialogFormVisible = true;
      this.loadDataing = true;

      api
        .getUserInfo(userId)
        .then((res) => {
          this.user.id = res.id;
          this.user.accountNo = res.accountNo;
          this.user.realName = res.realName;
          this.user.remark = res.remark;
          this.user.createUser = res.createUser;
          this.user.updateUser = this.$store.state.user.accountNo;
        })
        .catch(() => {})
        .finally(() => {
          this.loadDataing = false;
        });
    },
  },
};
</script>
